﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using System.Web.Routing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LOMBARDISPICK.Web;
using LOMBARDISPICK.Web.Controllers;
using LOMBARDISPICK.Domain.Services;
using Moq;
using System.IO;
using System.Security.Principal;
using LOMBARDISPICK.Tests.Infrastructure;
using FluentAssertions.Assertions;
using FluentAssertions.Common;
using FluentAssertions.EventMonitoring;
using FluentAssertions.Formatting;
using FluentAssertions;

namespace LOMBARDISPICK.Tests.Controllers
{
	[TestClass]
	public class GenericControllerLevelTests
	{
		[TestMethod]
		public void IndexReturnProperModel()
		{
			//
			// Arrange
			// Auto mocking allows you to get object of the type you want to test without setting up mocks by hand.
			var factory = new MockRepository(MockBehavior.Loose);
			var container = new AutoMockContainer(factory);
			var controller = container.Create<TeamSeason_1985_2011Controller>();
			factory.VerifyAll();
			//setup HttpContext
			controller.ControllerContext = new ControllerContext();
			controller.ControllerContext.HttpContext = MvcMockHelpers.FakeHttpContext("~/");

			//
			// Act
			ViewResult result = controller.Index() as ViewResult;

			//
			// Assert
			Assert.IsNotNull(result.ViewData.Model);
			Assert.IsInstanceOfType((object)result.ViewData.Model, typeof(IEnumerable<LOMBARDISPICK.Model.TeamSeason_1985_2011>));
		}

		[TestMethod]
		public void TestEmptyRoute()
		{
			// Arrange
			RouteCollection routeConfig = new RouteCollection();
			MvcApplication.RegisterRoutes(routeConfig);
			HttpContextBase testContext = MvcMockHelpers.FakeHttpContext("~/");
			// Act
			RouteData routeData = routeConfig.GetRouteData(testContext);
			// Assert
			routeData.Should().NotBeNull("because routeData explains the MVC route", "NULL RouteData was returned");
			Assert.IsNotNull(routeData, "NULL RouteData was returned");
			Assert.IsNotNull(routeData.Route, "No route was matched");
			Assert.AreEqual("Home", routeData.Values["controller"], "Wrong controller");
			Assert.AreEqual("Index", routeData.Values["action"], "Wrong action");
		}

		[TestMethod]
		public void CheckGeneratedURL()
		{
			string result = MvcMockHelpers.SetupUrlViaMocks(
			new { controller = "TeamSeason_1985_2011", action = "Edit", id = 10 }
			);
			Assert.AreEqual("/TeamSeason_1985_2011/Edit/10", result);
		}
	}
}
